

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

excelPath = 'D:/KLG/FINAL/code/testImgSave/CountResult.xlsx'
figurePath = 'D:/KLG/FINAL/code/testImgSave/Count.png'

plt.rcParams["font.sans-serif"] = ["SimHei"]  # 设置字体
plt.rcParams["axes.unicode_minus"] = False  # 正常显示负号

df = pd.read_excel(excelPath)

y = df.iloc[0, 1:].values
x = ['颗粒污泥', '累枝虫', '絮体', '轮虫', '丝状菌']
plt.xticks(range(len(y)), x)

plt.title('原始数据集微生物数量统计')
plt.xlabel('种类')
plt.ylabel('数量')
for i, v in enumerate(y):
    plt.text(i, v, str(round(v/sum(y)*100, 2)) + '%', ha='center', va='bottom')
plt.bar(range(len(y)), y)

plt.show()



